package com.lrs.java.jdbc.jdbc_teacher;

import java.sql.*;
//存储过程
class TestProc {

/*	--带参数的存储过程 (stored procedure)
	create or replace procedure p
	   (v_a in number, v_b number, v_ret out number, v_temp in out number )
	is

	begin
	   if (v_a > v_b) then
	      v_ret := v_a;
	   else
	      v_ret := v_b;
	   end if;
	   v_temp := v_temp + 1;
	end;


	declare
	   v_a number := 3;
	   v_b number := 4;
	   v_ret number;
	   v_temp number := 5;
	   
	begin
	   p(v_a, v_b, v_ret, v_temp);
	   dbms_output.put_line(v_ret);
	   dbms_output.put_line(v_temp);
	end;*/
	
	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
		
		Class.forName("oracle.jdbc.driver.OracleDriver");
		Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:BJSXT", "scott", "tiger");
		//CallableStatement 对象提供了设置其 IN 和 OUT 参数的方法，
		//以及用来执行对存储过程的调用的方法
		CallableStatement cstmt = conn.prepareCall("{call p(?, ?, ?, ?)}");
		cstmt.registerOutParameter(3, Types.INTEGER);
		cstmt.registerOutParameter(4, Types.INTEGER);
		cstmt.setInt(1, 3);
		cstmt.setInt(2, 4);
		cstmt.setInt(4, 5);
		cstmt.execute();
		System.out.println(cstmt.getInt(3));
		System.out.println(cstmt.getInt(4));
		cstmt.close();
		conn.close();
	}

}
